package com.beiyou.controller;

import cn.hutool.core.util.ObjectUtil;
import com.beiyou.dao.VenueDao;
import com.beiyou.model.Venue;
import com.beiyou.model.VenueQuery;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/yunji-api/venue")
public class VenueController {

    @Autowired
    private VenueDao venueDao;

    @PostMapping("/insert")
    public Integer insert(@RequestBody Venue venue){
      //省略校验
        return    venueDao.insert(venue);
    }

    @PutMapping("/update")
    public Integer update(@RequestBody Venue venue){
        //省略校验
        return    venueDao.update(venue);
    }

    @GetMapping("/select") // ?id=1&name=中华&pageSize=10&pageNum=3
    public PageInfo<Venue>  select(VenueQuery query){

        if(ObjectUtil.isNotEmpty(query.getPageNum()) && ObjectUtil.isNotEmpty(query.getPageSize())){
            PageHelper.startPage(query.getPageNum(), query.getPageSize());
        }

        List<Venue> venues = venueDao.select(query);
        PageInfo<Venue> PageInfo = new PageInfo<Venue>(venues);
        return PageInfo;

       // return  venueDao.select(query);
    }
    @DeleteMapping("/delete")
    public Integer delete(@RequestParam Integer id){
        ///校验合法性
      return   venueDao.delete(id);
    }
}
